package com.bootdo.system.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bootdo.common.utils.DateUtils;
import com.bootdo.common.utils.EmojiConverterUtil;
import com.bootdo.system.dao.MenuDao;
import com.bootdo.system.domain.TbScgl;
import com.bootdo.system.domain.TbScglExample;
import com.bootdo.system.domain.TbScglExample.Criteria;
import com.bootdo.system.mapper.TbScglMapper;
import com.bootdo.system.service.ScglService;

@Service
public class ScglServiceImpl implements ScglService{
	@Autowired
	TbScglMapper sm;
	
	@Override
	public List<TbScgl> list(Integer gzhId,int type) {
		TbScglExample tbScglExample = new TbScglExample();
		Criteria createCriteria = tbScglExample.createCriteria();
		if(gzhId != null) {
			createCriteria.andTypeEqualTo(type);
			createCriteria.andGzhIdEqualTo(gzhId);
			List<TbScgl> selectByExample = sm.selectByExample(tbScglExample);
			if(selectByExample != null && selectByExample.size() > 0) {
				for (TbScgl tbScgl : selectByExample) {
					String scms = tbScgl.getScms();
					String emojiRecovery2 = EmojiConverterUtil.emojiRecovery2(scms);
					tbScgl.setScms(emojiRecovery2);
				}
			}
			return selectByExample;
		}
		return null;
	}

	@Override
	public int insert2update(TbScgl table) {
		int res=0;
		if(table != null) {
			Integer id = table.getId();
			if(id != null) {
				table.setXgsj(DateUtils.format(new Date()));
				res=sm.updateByPrimaryKeySelective(table);
			}else {
				table.setCjsj(DateUtils.format(new Date()));
				res=sm.insertSelective(table);
			}
		}
		return res;
	}

	@Override
	public TbScgl getById(Integer id) {
		TbScgl selectByPrimaryKey = sm.selectByPrimaryKey(id);
		if(selectByPrimaryKey != null) {
			String scms = selectByPrimaryKey.getScms();
			String emojiRecovery2 = EmojiConverterUtil.emojiRecovery2(scms);
			selectByPrimaryKey.setScms(emojiRecovery2);
		}
		return selectByPrimaryKey;
	}

	@Override
	public int batchremove(Integer[] msgIds) {
		int res=0;
		if(msgIds.length > 0) {
			for (int i = 0; i < msgIds.length; i++) {
				res=sm.deleteByPrimaryKey(msgIds[i]);
			}
		}
		return res;
	}

}
